//****************************************时间选择*****************************************
/*
id:''         组件编号，唯一，必须
data:{
	formatType: 格式化类型
	type:0:月报,1:年报,2:季报,3:半年报,4:周报,5:旬报,6:日报
	years:{
		year:
		month:
		day:
	}
}             组件数据
callback:''   回调函数
*/
function RxDate() {
}

RxDate.init = function(id, data, callback) {
    var ctrl = document.getElementById(id);
    if (!ctrl) {
        ctrl = document.createElement("div");
    }
	
	ctrl.dispose = RxCommon.dispose;
    ctrl.dispose();
	
	if (id) {
    	ctrl.id = id;
	}
    ctrl.className = "rxdate";
    ctrl.rxtype = "RxDate";
    ctrl.topSelectType = "un";
    ctrl.callback = callback;
	if(!data){
		var newDate = new Date();
		data = {};
		data.type = 0;
		data.years = {};
		data.years.year = newDate.getFullYear();
		data.years.month = RxCommon.prefixZero(newDate.getMonth() + 1,2);
		data.formatType = {
			type0 : "YYYY-MM",
			type1 : "YYYY",
			type2 : "YYYY-J",
			type3 : "YYYY-B",
			type4 : "YYYY-W",
			type5 : "YYYY-MM-X",
			type6 : "YYYY-MM-DD"
		}
	}
    ctrl.data = data;
    
	ctrl.createPanel = function(){
		var datepane = RxCommon.ce(this, null, "div", "rxdate_datepane");
    	
    	var table = RxCommon.ce(datepane, null, "table", "rxdate_datepane_table");
    	
    	var trTop = RxCommon.ce(table, null, "tr", null);
    	var trCenter = RxCommon.ce(table, null, "tr", null);
    	var trbottom = RxCommon.ce(table, null, "tr", null);

	    this.tdTop = RxCommon.ce(trTop, null, "td", null);
	    this.tdCenter = RxCommon.ce(trCenter, null, "td", null);
	    this.tdbottom = RxCommon.ce(trbottom, null, "td", null);
	    
	    this.topPanel = ctrl.createTopPanel();
	    this.bottomPanel = ctrl.createBottomPanel();
	    
	    this.tdTop.appendChild(this.topPanel);
	    this.tdbottom.appendChild(this.bottomPanel);

		document.body.appendChild(this);
	}
	
	ctrl.createTopPanel = function(){
		var table = RxCommon.ce(null, this.id + "_topTable", "table", "rxdate_datepane_header");
    	
    	var tr = RxCommon.ce(table, null, "tr", null);
    	
    	var tdLt2 = RxCommon.ce(null, null, "td", "rxdate_datepane_cell");
    	var tdLt = RxCommon.ce(null, null, "td", "rxdate_datepane_cell");
    	var tdYear = RxCommon.ce(null, null, "td", "rxdate_datepane_cell");
    	var tdUn = RxCommon.ce(null, null, "td", "rxdate_datepane_cell");
    	var tdDay = RxCommon.ce(null, null, "td", "rxdate_datepane_cell");
    	var tdGt = RxCommon.ce(null, null, "td", "rxdate_datepane_cell");
    	var tdGt2 = RxCommon.ce(null, null, "td", "rxdate_datepane_cell");

	    tdLt2.innerHTML = "&lt;&lt;";
	    tdLt.innerHTML = "&lt;";
	    tdGt.innerHTML = "&gt;";
	    tdGt2.innerHTML = "&gt;&gt;";
	    
	    tdLt2.rxType = "--";
	    tdLt.rxType = "-";
	    tdGt.rxType = "+";
	    tdGt2.rxType = "++";
	    tdYear.rxType = "year";
	    tdUn.rxType = "un";
	    tdDay.rxType = "day";
	    
	    this.tdYear = tdYear;
	    this.tdUn = tdUn;
	    this.tdDay = tdDay;
	    
		if(this.data.type == 0){
			tdYear.innerHTML = this.data.years.year + "年";
			tdUn.innerHTML = RxCommon.prefixZero(this.data.years.month,2) + "月";
		}else if(this.data.type == 1){
			tdYear.innerHTML = this.data.years.year + "年";
		}else if(this.data.type == 2){
			tdYear.innerHTML = this.data.years.year + "年";
			tdUn.innerHTML = this.typeChange(this.data.years.month);
			$(tdUn).css("width", "500px");
		}else if(this.data.type == 3){
			tdYear.innerHTML = this.data.years.year + "年";
			if(this.data.years.month == "B" + 1){
				tdUn.innerHTML = "上半年";
			}else{
				tdUn.innerHTML = "下半年";
			}
			$(tdUn).css("width", "300px");
		}else if(this.data.type == 4){
			tdYear.innerHTML = this.data.years.year + "年";
			tdUn.innerHTML = this.typeChange(this.data.years.month);
			$(tdUn).css("width", "300px");
		}else if(this.data.type == 5){
			tdYear.innerHTML = this.data.years.year + "年";
			tdUn.innerHTML = this.data.years.month + "月";
			if(this.data.years.day == "X1"){
				tdDay.innerHTML = "上旬";
			}else if(this.data.years.day == "X2"){
				tdDay.innerHTML = "中旬";
			}else{
				tdDay.innerHTML = "下旬";
			}
		}else if(this.data.type == 6){
			tdYear.innerHTML = this.data.years.year + "年";
			tdUn.innerHTML = RxCommon.prefixZero(this.data.years.month,2) + "月";
			tdDay.innerHTML = RxCommon.prefixZero(this.data.years.day,2) + "日";
		}
		tr.appendChild(tdLt2);
		tr.appendChild(tdLt);
		if(this.data.type == 1){
			tr.appendChild(tdYear);
		}else if(this.data.type == 5 || this.data.type == 6){
			tr.appendChild(tdYear);
			tr.appendChild(tdUn);
			tr.appendChild(tdDay);
		}else{
			tr.appendChild(tdYear);
			tr.appendChild(tdUn);
		}
		tr.appendChild(tdGt);
		tr.appendChild(tdGt2);
		$(table).find('.rxdate_datepane_cell,.rxdate_datepane_cell_selected').click(function(){
			var rxType = "";
			if($(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0]){
				rxType = $(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].rxType;
					
			}
			if(this.rxType == "un"){
				ctrl.topSelectType = this.rxType;
				ctrl.cancelTopSelect();
				this.className = "rxdate_datepane_cell_selected";
				
				$(ctrl).find(".rxdate_datepane_detail").remove();
				if(ctrl.data.type == 4){
					var week = "";
					if(ctrl.data.years.month.indexOf("W") == -1){
						week = ctrl.getDateWeek(ctrl.getNewDate());
					}else{
						week = ctrl.data.years.month.replace("W", "");
					}
					if(week > 18){
						ctrl.startYear = week - 18 + 1;
					}else{
						ctrl.startYear = 0;
					}
				}
				ctrl.centerPanel = ctrl.createCenterPanel();
				ctrl.tdCenter.appendChild(ctrl.centerPanel);
			}else if(this.rxType == "year"){
				ctrl.topSelectType = this.rxType;
				ctrl.cancelTopSelect();
				this.className = "rxdate_datepane_cell_selected";
				$(ctrl).find(".rxdate_datepane_detail").remove();
				ctrl.startYear = ctrl.data.years.year - 18;
				ctrl.centerPanel = ctrl.createCenterPanel();
				ctrl.tdCenter.appendChild(ctrl.centerPanel);
			}else if(this.rxType == "day"){
				ctrl.topSelectType = this.rxType;
				ctrl.cancelTopSelect();
				this.className = "rxdate_datepane_cell_selected";
				$(ctrl).find(".rxdate_datepane_detail").remove();
				ctrl.centerPanel = ctrl.createCenterPanel();
				ctrl.tdCenter.appendChild(ctrl.centerPanel);
			}else if(this.rxType == "-"){	
				if(rxType == "year" || rxType == "un" && ctrl.data.type == 4){
					$(ctrl).find(".rxdate_datepane_detail").remove();
					if(ctrl.data.type == 4 && rxType == "un"){
						if(ctrl.startYear - 10 < 0){
							ctrl.startYear = 0;
						}else{
							ctrl.startYear = ctrl.startYear - 10;
						}
					}else{
						ctrl.startYear = ctrl.startYear - 10;
					}
					ctrl.centerPanel = ctrl.createCenterPanel();
					ctrl.tdCenter.appendChild(ctrl.centerPanel);
				}
			}else if(this.rxType == "--"){
				if(rxType == "year" || rxType == "un" && ctrl.data.type == 4){
					$(ctrl).find(".rxdate_datepane_detail").remove();
					if(ctrl.data.type == 4 && rxType == "un"){
						if(ctrl.startYear - 30 < 0){
							ctrl.startYear = 0;
						}else{
							ctrl.startYear = ctrl.startYear - 30;
						}
					}else{
						ctrl.startYear = ctrl.startYear - 30;
					}
					ctrl.centerPanel = ctrl.createCenterPanel();
					ctrl.tdCenter.appendChild(ctrl.centerPanel);
				}
			}else if(this.rxType == "+"){
				if(rxType == "year" || rxType == "un" && ctrl.data.type == 4){
					$(ctrl).find(".rxdate_datepane_detail").remove();
					if(ctrl.data.type == 4 && rxType == "un"){
						if(ctrl.startYear + 10 > 24){
							ctrl.startYear = 23;
						}else{
							ctrl.startYear = ctrl.startYear + 10;
						}
					}else{
						ctrl.startYear = ctrl.startYear + 10;
					}
					ctrl.centerPanel = ctrl.createCenterPanel();
					ctrl.tdCenter.appendChild(ctrl.centerPanel);
				}
			}else if(this.rxType == "++"){
				if(rxType == "year" || rxType == "un" && ctrl.data.type == 4){
					$(ctrl).find(".rxdate_datepane_detail").remove();
					if(ctrl.data.type == 4 && rxType == "un"){
						if(ctrl.startYear + 30 > 24){
							ctrl.startYear = 23;
						}else{
							ctrl.startYear = ctrl.startYear + 30;
						}
					}else{
						ctrl.startYear = ctrl.startYear + 30;
					}
					ctrl.centerPanel = ctrl.createCenterPanel();
					ctrl.tdCenter.appendChild(ctrl.centerPanel);
				}
			}
		})
		return table;
	}
	
	ctrl.createCenterPanel = function(){
		var table = RxCommon.ce(null, this.id + "_centerTable", "table", "rxdate_datepane_detail");
    	var tr,td;

		if(this.topSelectType == "year"){
			var startYear = this.startYear;
			
			for(var i = 0; i < 6; i++){
				tr = RxCommon.ce(table, null, "tr", null);
		    	for(var j = 0; j < 5; j++){
		    		startYear = startYear + 1;
		    		
		    		td = RxCommon.ce(tr, null, "td", null);
			    	td.rxType = "unValue";
			    	if(this.data.years.year == startYear){
				    	td.className = "rxdate_datepane_cell_selected";
					}else{
						td.className = "rxdate_datepane_cell";
					}
					if(this.getNewDate().year == startYear){
				    	td.style.border = "solid 1px red";
					}
					if(startYear < 0){
						td.innerHTML = "0" + startYear;
					}else{
						td.innerHTML = startYear;
					}
				}
			}
		}else if(this.topSelectType == "day"){
			if(this.data.type == 5){
				tr = RxCommon.ce(table, null, "tr", null);
			    for(var j = 1; j <= 3; j++){
			    	td = RxCommon.ce(tr, null, "td", null);
			    	td.rxType = "unValue";
			    	if(j == 1){
					    td.innerHTML = "上旬";
					}else if(j == 2){
						td.innerHTML = "中旬";
					}else{
						td.innerHTML = "下旬";
					}
					td.values = "X" + j;
					if(this.data.years.day == "X" + j){
				    	td.className = "rxdate_datepane_cell_selected";
					}else{
						td.className = "rxdate_datepane_cell";
					}
					if(this.getDatePeriod(this.getNewDate().day).name == td.innerHTML){
				    	td.style.border = "solid 1px red";
					}
				}
			}else if(this.data.type == 6){
				var countDays = this.getCountDays(this.data.years);
				var row = countDays <= 30 ? 6 : 7;
				
				for(var i = 0; i < row; i++){
					tr = RxCommon.ce(table, null, "tr", null);
			    	for(var j = 1; j <= 5; j++){
						var day = i * 5 + j;
						
			    		td = RxCommon.ce(tr, null, "td", null);
				    	td.rxType = "unValue";
						td.values = day;
						if(day <= countDays){
							 if(this.data.years.day == day){
						    	td.className = "rxdate_datepane_cell_selected";
							}else{
								td.className = "rxdate_datepane_cell";
							}
				    		td.innerHTML = day;
				    	}
				    	if(this.getNewDate().day == day){
				    		td.style.border = "solid 1px red";
						}
					}
				}
			}
		}else if(this.topSelectType == "un"){
			if(this.data.type == 0 || this.data.type == 5 || this.data.type == 6){
				for(var i = 0; i < 2; i++){
			    	tr = RxCommon.ce(table, null, "tr", null);
				    for(var j = 1; j <= 6; j++){
				    	td = RxCommon.ce(tr, null, "td", null);
				    	td.rxType = "unValue";
					    if(i == 1){
					    	if(this.data.years.month == j + 6){
						    	td.className = "rxdate_datepane_cell_selected";
							}else{
								td.className = "rxdate_datepane_cell";
							}
						    td.innerHTML = RxCommon.prefixZero(j + 6, 2);
						    td.values = j + 6;
						    if(this.getNewDate().month == (j + 6)){
				    			td.style.border = "solid 1px red";
							}
						}else{
							if(this.data.years.month == j){
							    td.className = "rxdate_datepane_cell_selected";
							}else{
								td.className = "rxdate_datepane_cell";
							}
							td.innerHTML = RxCommon.prefixZero(j, 2);
							td.values = j;
							if(this.getNewDate().month == j){
				    			td.style.border = "solid 1px red";
							}
						}
				    }
			    }
			}else if(this.data.type == 2){
				for(var i = 0; i < 2; i++){
			    	tr = RxCommon.ce(table, null, "tr", null);
				    for(var j = 1; j <= 2; j++){
				    	td = RxCommon.ce(tr, null, "td", null);
				    	td.rxType = "unValue";
				    	if(i == 1){
					    	if(this.data.years.month == "J" + (j + 2)){
						    	td.className = "rxdate_datepane_cell_selected";
							}else{
								td.className = "rxdate_datepane_cell";
							}
						    td.innerHTML = "第" + (j + 2) + "季度";
						    td.values = "J" + (j + 2);
						    if(td.innerHTML == ctrl.typeChange(this.getNewDate().month)){
				    			td.style.border = "solid 1px red";
							}
						}else{
							if(this.data.years.month == "J" + j){
							    td.className = "rxdate_datepane_cell_selected";
							}else{
								td.className = "rxdate_datepane_cell";
							}
							td.innerHTML = "第" + j + "季度";
							td.values = "J" + j;
							if(td.innerHTML == ctrl.typeChange(this.getNewDate().month)){
				    			td.style.border = "solid 1px red";
							}
						}
					}
				}
			}else if(this.data.type == 3){
		    	tr = RxCommon.ce(table, null, "tr", null);
			    for(var j = 1; j <= 2; j++){
			    	td = RxCommon.ce(tr, null, "td", null);
			    	td.rxType = "unValue";
			    	if(this.data.years.month == "B" + j){
				    	td.className = "rxdate_datepane_cell_selected";
					}else{
						td.className = "rxdate_datepane_cell";
					}
					if(j == 1){
				    	td.innerHTML = "上半年";
					}else{
						td.innerHTML = "下半年";
					}
					if(td.innerHTML == ctrl.typeChange(this.getNewDate().month)){
		    			td.style.border = "solid 1px red";
					}
					td.values = "B" + j;
				}
			}else if(this.data.type == 4){
				var startWeek = this.startYear;
				for(var i = 0; i < 6; i++){
					tr = RxCommon.ce(table, null, "tr", null);
			    	for(var j = 0; j < 5; j++){
			    		startWeek = startWeek + 1;
				    	if(startWeek > 53){
				    		break;
				    	}
			    		td = RxCommon.ce(tr, null, "td", null);
				    	td.rxType = "unValue";
				    	if(this.data.years.month == "W" + startWeek){
					    	td.className = "rxdate_datepane_cell_selected";
						}else{
							td.className = "rxdate_datepane_cell";
						}
						if(startYear < 0){
							td.innerHTML = "0" + startWeek + "周";
						}else{
							td.innerHTML = startWeek + "周";
						}
						if(startWeek == this.getDateWeek(this.getNewDate())){
		    				td.style.border = "solid 1px red";
						}
			    		td.values = "W" + startWeek;
					}
				}
			}
	    }
		$(table).find('.rxdate_datepane_cell,.rxdate_datepane_cell_selected').click(function(){
			if($(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].rxType == "year"){
				ctrl.data.years.year = this.innerHTML;
				$(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].innerHTML = this.innerHTML + "年";
				if($(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0]){
					$(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0].className = "rxdate_datepane_cell";
				}
				this.className = "rxdate_datepane_cell_selected";
				if(ctrl.data.type == 1){
					ctrl._self.setValue(ctrl.getValue());
					ctrl.callback({id:ctrl.id, name:"click", self: ctrl._self, source:ctrl, value:ctrl.getValueObject()});
					$(ctrl).hide();
				}
				ctrl.tdUn.click();
			}else if($(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].rxType == "un"){
				if(ctrl.data.type == 0){
					ctrl.data.years.month = this.innerHTML;
					$(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].innerHTML = this.innerHTML + "月";
					$(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0].className = "rxdate_datepane_cell";
					this.className = "rxdate_datepane_cell_selected";
				}else if(ctrl.data.type == 2){
					ctrl.data.years.month = this.values;
					$(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].innerHTML = this.innerHTML;
					$(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0].className = "rxdate_datepane_cell";
					this.className = "rxdate_datepane_cell_selected";
				}else if(ctrl.data.type == 3){
					ctrl.data.years.month = this.values;
					$(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].innerHTML = this.innerHTML;
					$(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0].className = "rxdate_datepane_cell";
					this.className = "rxdate_datepane_cell_selected";
				}else if(ctrl.data.type == 4){
					ctrl.data.years.month = this.values;
					$(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].innerHTML = "第" + this.innerHTML;
					if($(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0]){
						$(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0].className = "rxdate_datepane_cell";
					}
					this.className = "rxdate_datepane_cell_selected";
				}
				if(ctrl.data.type == 5){
					ctrl.data.years.month = this.values;
					$(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].innerHTML = this.innerHTML + "月";
					if($(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0]){
						$(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0].className = "rxdate_datepane_cell";
					}
					this.className = "rxdate_datepane_cell_selected";
					ctrl.tdDay.click();
				}else if(ctrl.data.type == 6){
					ctrl.data.years.month = this.values;
					$(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].innerHTML = this.innerHTML + "月";
					if($(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0]){
						$(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0].className = "rxdate_datepane_cell";
					}
					this.className = "rxdate_datepane_cell_selected";
					ctrl.tdDay.click();
				}else{
					ctrl.callback({id:ctrl.id, name:"click", self: ctrl._self, source:ctrl, value:ctrl.getValueObject()});
					ctrl._self.setValue(ctrl.getValue());
					$(ctrl).hide();
				}
			}else{
				if(ctrl.data.type == 5){
					ctrl.data.years.day = this.values;
					$(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].innerHTML = this.innerHTML;
					$(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0].className = "rxdate_datepane_cell";
					this.className = "rxdate_datepane_cell_selected";
				}else{
					ctrl.data.years.day = this.values;
					$(ctrl).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].innerHTML = RxCommon.prefixZero(this.innerHTML, 2) + "日";
					$(ctrl).find(".rxdate_datepane_detail .rxdate_datepane_cell_selected")[0].className = "rxdate_datepane_cell";
					this.className = "rxdate_datepane_cell_selected";
				}
				ctrl.callback({id:ctrl.id, name:"click", self: ctrl._self, source:ctrl, value:ctrl.getValueObject()});
				ctrl._self.setValue(ctrl.getValue());
				$(ctrl).hide();
			}
		})
			
	    return table;
	}

	ctrl.createBottomPanel = function(){
		var table = RxCommon.ce(null, this.id + "_BottomTable", "table", "rxdate_datepane_footer");
    	
    	var tr = RxCommon.ce(table, null, "tr", null);
    	
    	var tdc = RxCommon.ce(tr, null, "td", "rxdate_datepane_cell");
    	var tdt = RxCommon.ce(tr, null, "td", "rxdate_datepane_cell");
    	var tdo = RxCommon.ce(tr, null, "td", "rxdate_datepane_cell");

    	tdc.innerHTML = "清除";
    	tdt.innerHTML = "当前日期";
    	tdo.innerHTML = "确定";
    	
    	tdc.rxType = "clear";
		tdt.rxType = "newDate";
		tdo.rxType = "ok";
		
		$(table).find('.rxdate_datepane_cell,.rxdate_datepane_cell_selected').click(function(){
			if(this.rxType == "ok"){
				if(ctrl.data.type == 1){
					ctrl.tdYear.click();
				}
				ctrl._self.setValue(ctrl.getValue());
				ctrl.callback({id:ctrl.id, name:"click", self: ctrl._self, source:ctrl, value:ctrl.getValueObject()});
				$(ctrl).hide();
			}else if(this.rxType == "clear"){
				var date = ctrl.getNewDate();
				ctrl.setProDateValue(date);
				ctrl.typeRefresh(date);
				ctrl._self.setValue("");
				ctrl.callback({id:ctrl.id, name:"click", self: ctrl._self, source:ctrl, value:ctrl.getValueObject()});
				$(ctrl).hide();
			}else if(this.rxType == "newDate"){
				var date = ctrl.getNewDate();
				ctrl.setProDateValue(date);
				ctrl.typeRefresh(date);
				ctrl._self.setValue(ctrl.getValue());
				ctrl.callback({id:ctrl.id, name:"click", self: ctrl._self, source:ctrl, value:ctrl.getValueObject()});
				$(ctrl).hide();
			}
		})
		
    	return table;
	};
	ctrl.cancelTopSelect = function(){
		var len = $(this).find(".rxdate_datepane_header .rxdate_datepane_cell_selected").length;
			if(len != 0){
				$(this).find(".rxdate_datepane_header .rxdate_datepane_cell_selected")[0].className = "rxdate_datepane_cell";
			}
	};

    //获取业务日期
    ctrl.getValueObject = function() {
		var data = {};
		data.year = this.data.years.year;
		data.month = this.data.years.month;
		data.day = this.data.years.day;
        return data;
    };
    //设置业务日期
    ctrl.setValue = function(data) {
		this.setProDateValue(data);
		this.typeRefresh(data);
		this._self.setValue(this.getValue());
    };
    //获取系统日期
    ctrl.getNewDate = function() {
    	var data = {};
		var newDate = new Date();
		data.year = newDate.getFullYear();
		data.month = RxCommon.prefixZero(newDate.getMonth() + 1,2);
		data.day = newDate.getDate();
        return data;
    };
    //设置业务日期的值
    ctrl.setProDateValue = function(data) {
		this.data.years.year = data.year;
		if(this.data.type == 0 || this.data.type == 5 || this.data.type == 6){
			this.data.years.month = data.month;
		}else if(this.data.type == 2){
			this.data.years.month = "J" + Math.floor((data.month % 3 == 0 ? (data.month / 3) : (data.month / 3 + 1)));
		}else if(this.data.type == 3){
			this.data.years.month = parseInt(data.month) < 7 ? "B1" : "B2";
		}else if(this.data.type == 4){
			this.data.years.month = "W" + ctrl.getDateWeek(data);
		}else{
			this.data.years.month = null;
		}
		if(this.data.type == 5){
			this.data.years.day = ctrl.getDatePeriod(data.day).periodType;
		}else if(this.data.type == 6){
			this.data.years.day = data.day;
		}else{
			this.data.years.day = null;
		}
    };
    //获取某年某月有多少天
    ctrl.getCountDays = function(data) {
		var curDate = new Date(data.year, data.month, data.day);
		var curMonth = curDate.getMonth();
		curDate.setDate(0);
		return curDate.getDate();
    };
    //获取系统日期属于哪一周
    ctrl.getDateWeek = function(data) {
		var year = data.year;
		var d = new Date(year,0,1);
		var to = new Date(year+1,0,1);
		var i = 1;
		for(var from = d; from.getFullYear() < to.getFullYear(); ){
			var startMonth = from.getMonth() + 1;
			var startDay = from.getDate();
			from.setDate(from.getDate() + 6);
			var endMonth = from.getMonth() + 1;
			var endDay = from.getDate();
			from.setDate(from.getDate() + 1);
			if(startMonth == parseInt(data.month) || endMonth == parseInt(data.month)){
				if(startMonth == endMonth){
					if(startDay <= data.day && endDay >= data.day){
						break;
					}
				}else{
					endDay = this.getCountDays(data) + endDay;
					if(startDay <= data.day && endDay >= data.day){
						break;
					}
				}
			}
			i++;
		}
		return i;
    };
    //获取系统日期的周期（上、中、下旬）
    ctrl.getDatePeriod = function(day) {
    	var period = {};
		if(day <= 10){
			period.name = "上旬";
			period.periodType = "X1"
		}else if(10 < day && day <= 20){
			period.name = "中旬";
			period.periodType = "X2"
		}else{
			period.name = "下旬";
			period.periodType = "X3"
		}
		return period;
    };
    //获取要展示的值
    ctrl.getValue = function() {
		var year = this.data.years.year + "";
		var month = this.data.years.month + "";
		var day = this.data.years.day + "";
		var type = this.data.type;
		var showValue = "";
		if(type == 0){
			var yearFormat = "YYYY";
			var monthFormat = "MM";
			if(this.data.formatType.type0.indexOf("YYYY") == -1){
				year = year.substring(2, 4);
				yearFormat = "YY"
			}
			if(this.data.formatType.type0.indexOf("MM") == -1){
				month = parseInt(month);
				monthFormat = "M";
			}else{
				month = RxCommon.prefixZero(month,2);
			}
			showValue = this.data.formatType.type0.replace(yearFormat, year).replace(monthFormat, month).replace("Y", "");
		}else if(type == 1){
			var yearFormat = "YYYY";
			if(this.data.formatType.type1.indexOf("YYYY") == -1){
				year = year.substring(2, 4);
				yearFormat = "YY"
			}
			showValue = this.data.formatType.type1.replace(yearFormat, year);
		}else if(type == 2 || type == 3 || type == 4){
			var yearFormat = "YYYY";
			var J = "J",B = "B",W = "W";
			
			if(type == 2){
				if(this.data.formatType.type2.indexOf("YYYY") == -1){
					year = year.substring(2, 4);
					yearFormat = "YY"
				}
				showValue = this.data.formatType.type2.replace(yearFormat, year).replace(J, ctrl.typeChange(month)).replace("Y", "");
			}else if(type == 3){
				if(this.data.formatType.type3.indexOf("YYYY") == -1){
					year = year.substring(2, 4);
					yearFormat = "YY"
				}
				showValue = this.data.formatType.type3.replace(yearFormat, year).replace(B, ctrl.typeChange(month)).replace("Y", "");
			}else if(type == 4){
				if(this.data.formatType.type4.indexOf("YYYY") == -1){
					year = year.substring(2, 4);
					yearFormat = "YY"
				}
				showValue = this.data.formatType.type4.replace(yearFormat, year).replace(W, ctrl.typeChange(month)).replace("Y", "");
			}
		}else if(type == 5){
			var yearFormat = "YYYY";
			var monthFormat = "MM";
			var X = "X"
			if(this.data.formatType.type5.indexOf("YYYY") == -1){
				year = year.substring(2, 4);
				yearFormat = "YY"
			}
			if(this.data.formatType.type5.indexOf("MM") == -1){
				month = parseInt(month);
				monthFormat = "M";
			}else{
				month = RxCommon.prefixZero(month,2);
			}
			showValue = this.data.formatType.type5.replace(yearFormat, year).replace(monthFormat, month).replace(X, ctrl.typeChange(day)).replace("Y", "");
		}else if(type == 6){
			var yearFormat = "YYYY";
			var monthFormat = "MM";
			var dayFormat = "DD";
			var D = "D"
			if(this.data.formatType.type6.indexOf("YYYY") == -1){
				year = year.substring(2, 4);
				yearFormat = "YY"
			}
			if(this.data.formatType.type6.indexOf("MM") == -1){
				month = parseInt(month);
				monthFormat = "M";
			}else{
				month = RxCommon.prefixZero(month,2);
			}
			if(this.data.formatType.type6.indexOf("DD") == -1){
				day = parseInt(day);
				dayFormat = "D";
			}else{
				day = RxCommon.prefixZero(day,2);
			}
			showValue = this.data.formatType.type6.replace(yearFormat, year).replace(monthFormat, month).replace(dayFormat, day).replace("Y", "");
		}
		return showValue;
    };
    //将业务类型转换为文字
    ctrl.typeChange = function(data) {
		if(this.data.type == 2){
			if(data.indexOf("J") == -1){
				data = "第" + Math.floor((data % 3 == 0 ? (data / 3) : (data / 3 + 1))) + "季度";
			}else{
				data = "第" + data.replace("J","") + "季度";
			}
		}else if(this.data.type == 3){
			if(data == "B1" || parseInt(data) < 7){
				data = "上半年";
			}else{
				data = "下半年";
			}
		}else if(this.data.type == 4){
			data = "第" + (data + "").replace("W","") + "周";
		}else if(this.data.type == 5){
			if(data == "X1"){
				data = "上旬";
			}else if(data == "X2"){
				data = "中旬";
			}else{
				data = "下旬";
			}
		}
		return data;
    };

    //将业务类型转换为文字
    ctrl.typeRefresh = function(date) {
		if(this.data.type == 0){
			this.tdYear.innerHTML = date.year + "年";
			this.tdUn.innerHTML = date.month + "月";
			this.tdUn.click();
		}else if(this.data.type == 1){
			this.tdYear.innerHTML = date.year + "年";
			this.tdYear.click();
		}else if(this.data.type == 2){
			this.tdYear.innerHTML = date.year + "年";
			this.tdUn.innerHTML = this.typeChange(date.month);
			this.tdUn.click();
		}else if(this.data.type == 3){
			this.tdYear.innerHTML = date.year + "年";
			this.tdUn.innerHTML = this.typeChange(date.month);
			this.tdUn.click();
		}else if(this.data.type == 4){
			this.tdYear.innerHTML = date.year + "年";
			this.tdUn.innerHTML = "第" + this.getDateWeek(this.getNewDate()) + "周";
			this.tdUn.click();
		}else if(this.data.type == 5){
			this.tdYear.innerHTML = date.year + "年";
			this.tdUn.innerHTML = date.month + "月";
			this.tdDay.innerHTML = this.getDatePeriod(date.day).name;
			this.tdDay.click();
		}else if(this.data.type == 6){
			this.tdYear.innerHTML = date.year + "年";
			this.tdUn.innerHTML = date.month + "月";
			this.tdDay.innerHTML = date.day + "日";
			this.tdDay.click();
		}
    };
    
	ctrl.createPanel();

	if(ctrl.data.type == 1){
		ctrl.tdYear.click();
	}else if(ctrl.data.type == 5 || ctrl.data.type == 6){
		ctrl.tdDay.click();
	}else{
		ctrl.tdUn.click();
	}
	
	return ctrl;
}
//ED*****************************************树型、列表型组件*****************************************